import 'package:my_soft/pages/home/appbar.dart';
import 'package:my_soft/pages/home/list_tile.dart';
import 'package:my_soft/pages/home/logic.dart';
import 'package:my_soft/pages/home/searchbar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class HomePage extends StatelessWidget {
  HomePage({super.key});

  final logic = Get.put(HomeLogic());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: RefreshIndicator(
        onRefresh: onRefresh,
        child: CustomScrollView(
          scrollDirection: Axis.vertical,
          controller: logic.scrollController,
          slivers: [
            BuildAppBar(),
            BuildSeachbar(),
            // BuildTabbar(),
            Obx(() {
              return buildList();
            }),
            // SliverAnimatedList(
            //   // Todo ----- 列表动画
            //   initialItemCount: logic.appList.length,
            //   itemBuilder: (context, i, animation) {
            //     return AppListTile(item: logic.appList.toList()[i]);
            //   },
            // )
          ],
        ),
      ),
    );
  }

  Future onRefresh() async {
    //......实现刷新逻辑
    debugPrint("实现刷新逻辑---->");
    logic.appList.value = List.from(logic.appListBackup);
  }

  buildList() {
    return SliverFixedExtentList(
      // 子条目的高度
      itemExtent: 80,
      // 子条目布局构建代理
      delegate: SliverChildBuilderDelegate(
          // 子条目的个数
          childCount: logic.appList.length,
          //  子条目的布局样式
          (_, int i) => AppListTile(
                item: logic.appList.toList()[i],
                index: i,
              )),
    );
  }
}
